from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-20 14:03:57.855364
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 20, Jan, 2022
Time: 14:04:03
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.7721
Nobs: 542.000 HQIC: -48.2065
Log likelihood: 6307.95 FPE: 8.77172e-22
AIC: -48.4854 Det(Omega_mle): 7.44092e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.366314 0.070481 5.197 0.000
L1.Burgenland 0.102504 0.042681 2.402 0.016
L1.Kärnten -0.113694 0.022104 -5.144 0.000
L1.Niederösterreich 0.191628 0.088951 2.154 0.031
L1.Oberösterreich 0.121971 0.088166 1.383 0.167
L1.Salzburg 0.263348 0.045128 5.836 0.000
L1.Steiermark 0.026253 0.059500 0.441 0.659
L1.Tirol 0.106988 0.047972 2.230 0.026
L1.Vorarlberg -0.076312 0.042425 -1.799 0.072
L1.Wien 0.017664 0.078167 0.226 0.821
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.065716 0.153576 0.428 0.669
L1.Burgenland -0.043918 0.093001 -0.472 0.637
L1.Kärnten 0.040257 0.048165 0.836 0.403
L1.Niederösterreich -0.204703 0.193822 -1.056 0.291
L1.Oberösterreich 0.450192 0.192112 2.343 0.019
L1.Salzburg 0.286521 0.098333 2.914 0.004
L1.Steiermark 0.111654 0.129649 0.861 0.389
L1.Tirol 0.308165 0.104530 2.948 0.003
L1.Vorarlberg 0.020609 0.092443 0.223 0.824
L1.Wien -0.025306 0.170324 -0.149 0.882
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197675 0.035985 5.493 0.000
L1.Burgenland 0.090259 0.021791 4.142 0.000
L1.Kärnten -0.007469 0.011286 -0.662 0.508
L1.Niederösterreich 0.236184 0.045415 5.201 0.000
L1.Oberösterreich 0.167515 0.045015 3.721 0.000
L1.Salzburg 0.039679 0.023041 1.722 0.085
L1.Steiermark 0.024694 0.030379 0.813 0.416
L1.Tirol 0.081521 0.024493 3.328 0.001
L1.Vorarlberg 0.053947 0.021661 2.491 0.013
L1.Wien 0.117618 0.039909 2.947 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.119440 0.036056 3.313 0.001
L1.Burgenland 0.043054 0.021835 1.972 0.049
L1.Kärnten -0.014249 0.011308 -1.260 0.208
L1.Niederösterreich 0.173447 0.045505 3.812 0.000
L1.Oberösterreich 0.334001 0.045104 7.405 0.000
L1.Salzburg 0.101777 0.023086 4.409 0.000
L1.Steiermark 0.109655 0.030439 3.602 0.000
L1.Tirol 0.091636 0.024541 3.734 0.000
L1.Vorarlberg 0.057177 0.021704 2.634 0.008
L1.Wien -0.016295 0.039988 -0.407 0.684
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118937 0.068242 1.743 0.081
L1.Burgenland -0.044824 0.041325 -1.085 0.278
L1.Kärnten -0.045248 0.021402 -2.114 0.034
L1.Niederösterreich 0.141430 0.086125 1.642 0.101
L1.Oberösterreich 0.168498 0.085365 1.974 0.048
L1.Salzburg 0.281871 0.043694 6.451 0.000
L1.Steiermark 0.063131 0.057610 1.096 0.273
L1.Tirol 0.153771 0.046448 3.311 0.001
L1.Vorarlberg 0.093734 0.041077 2.282 0.022
L1.Wien 0.072465 0.075683 0.957 0.338
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.092930 0.053040 1.752 0.080
L1.Burgenland 0.019128 0.032119 0.596 0.551
L1.Kärnten 0.052375 0.016634 3.149 0.002
L1.Niederösterreich 0.191822 0.066939 2.866 0.004
L1.Oberösterreich 0.323619 0.066348 4.878 0.000
L1.Salzburg 0.039251 0.033961 1.156 0.248
L1.Steiermark -0.002395 0.044776 -0.053 0.957
L1.Tirol 0.124222 0.036101 3.441 0.001
L1.Vorarlberg 0.063187 0.031926 1.979 0.048
L1.Wien 0.097129 0.058823 1.651 0.099
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.168160 0.064284 2.616 0.009
L1.Burgenland 0.007008 0.038928 0.180 0.857
L1.Kärnten -0.065074 0.020161 -3.228 0.001
L1.Niederösterreich -0.108929 0.081130 -1.343 0.179
L1.Oberösterreich 0.217555 0.080414 2.705 0.007
L1.Salzburg 0.050672 0.041160 1.231 0.218
L1.Steiermark 0.253923 0.054269 4.679 0.000
L1.Tirol 0.496491 0.043754 11.347 0.000
L1.Vorarlberg 0.065261 0.038695 1.687 0.092
L1.Wien -0.081087 0.071294 -1.137 0.255
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.159775 0.071135 2.246 0.025
L1.Burgenland -0.006671 0.043077 -0.155 0.877
L1.Kärnten 0.062356 0.022309 2.795 0.005
L1.Niederösterreich 0.178311 0.089777 1.986 0.047
L1.Oberösterreich -0.066335 0.088984 -0.745 0.456
L1.Salzburg 0.205624 0.045547 4.515 0.000
L1.Steiermark 0.137054 0.060052 2.282 0.022
L1.Tirol 0.056797 0.048417 1.173 0.241
L1.Vorarlberg 0.144267 0.042819 3.369 0.001
L1.Wien 0.132011 0.078892 1.673 0.094
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.395465 0.041533 9.522 0.000
L1.Burgenland -0.003536 0.025151 -0.141 0.888
L1.Kärnten -0.020712 0.013026 -1.590 0.112
L1.Niederösterreich 0.203606 0.052417 3.884 0.000
L1.Oberösterreich 0.241347 0.051955 4.645 0.000
L1.Salzburg 0.034188 0.026593 1.286 0.199
L1.Steiermark -0.017259 0.035062 -0.492 0.623
L1.Tirol 0.087123 0.028269 3.082 0.002
L1.Vorarlberg 0.050127 0.025000 2.005 0.045
L1.Wien 0.033345 0.046062 0.724 0.469
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.033979 0.100883 0.165553 0.136360 0.087584 0.083435 0.030587 0.212352
Kärnten 0.033979 1.000000 -0.026628 0.133575 0.047913 0.083971 0.446605 -0.069424 0.093576
Niederösterreich 0.100883 -0.026628 1.000000 0.307597 0.126159 0.266116 0.068125 0.156842 0.281196
Oberösterreich 0.165553 0.133575 0.307597 1.000000 0.214939 0.292306 0.170400 0.136171 0.233334
Salzburg 0.136360 0.047913 0.126159 0.214939 1.000000 0.128616 0.087231 0.105435 0.127161
Steiermark 0.087584 0.083971 0.266116 0.292306 0.128616 1.000000 0.138929 0.104309 0.029201
Tirol 0.083435 0.446605 0.068125 0.170400 0.087231 0.138929 1.000000 0.064252 0.150681
Vorarlberg 0.030587 -0.069424 0.156842 0.136171 0.105435 0.104309 0.064252 1.000000 -0.004723
Wien 0.212352 0.093576 0.281196 0.233334 0.127161 0.029201 0.150681 -0.004723 1.000000